<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <cpn></cpn>
    </div>


    <template id="cpn">
        <div>
            <h1>我是cpn组件</h1>
            <ccpn></ccpn>
        </div>
    </template>

    <template id="ccpn">
        <div>
            <h1>我是子组件</h1>
            <button @click="btnclick">button</button>
        </div>
    </template>

    <script src="../vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data() {
                return {
                    name: 'grandpa'
                }
            },
            components: {
                cpn: {
                    template: '#cpn',
                    data() {
                        return {
                            name: 'wyb'
                        }
                    },
                    components: {
                        ccpn: {
                            template: '#ccpn',
                            methods: {
                                btnclick() {
                                    console.log(this.$parent.name);
                                    console.log(this.$root.name);
                                }
                            }
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>